home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2000 / MacHack 2000.toast / pc / The Hacks / Softshoe / Lisa's Mac Parts / Application / ApplicationBase.cp < prev    next >
Text File  |  2000-06-23  |  2KB  |  107 lines

  1. // ApplicationBase.cp
  2.  
  3. #ifndef ApplicationBase_h
  4. #include "ApplicationBase.h"
  5. #endif
  6. #ifndef EventQueue_h
  7. #include "EventQueue.h"
  8. #endif
  9. #ifndef BroadcastLoop_h
  10. #include "BroadcastLoop.h"
  11. #endif
  12. #ifndef OSError_h
  13. #include "OSError.h"
  14. #endif
  15. #ifndef AEEvent_h
  16. #include "AEEvent.h"
  17. #endif
  18. #ifndef UserState_h
  19. #include "UserState.h"
  20. #endif
  21. #ifndef ProcessInfo_h
  22. #include "ProcessInfo.h"
  23. #endif
  24. #ifndef Commander_h
  25. #include "Commander.h"
  26. #endif
  27. #ifndef Quitter_h
  28. #include "Quitter.h"
  29. #endif
  30. #ifndef ApplicationFocus_h
  31. #include "ApplicationFocus.h"
  32. #endif
  33.  
  34. #include <Errors.h>
  35.  
  36. ApplicationBase *ApplicationBase::the = 0;
  37.  
  38. ApplicationBase::ApplicationBase( uint32 masterPointers,
  39.                                              uint32 extraStackSpace )
  40.   : ApplicationZoneUser( masterPointers, extraStackSpace )
  41.   {        
  42.     Assert( the == 0 );
  43.     the = this;
  44.     
  45.     Assert( !ProcessInfo::Application().IsDeskAccessory() );
  46.     Assert( ProcessInfo::Application().HighLevelEventAware() );
  47.     Assert( ProcessInfo::Application().CleanFor32Bits() );
  48.   }
  49.  
  50. ApplicationBase::~ApplicationBase()
  51.   {
  52.   }
  53.  
  54. void ApplicationBase::Run()
  55.   {
  56.     ApplicationFocus::The().SynchronizeWithProcessManager();
  57.     UserState::The().Announce();
  58.     
  59.     for ( EventQueue& queue( EventQueue::The() );
  60.             queue.Unfinished();
  61.             queue++ )
  62.       {
  63.         try
  64.           {
  65.             HandleEvent( *queue );
  66.           }
  67.          catch ( ... )
  68.           {
  69.             Assert( 0 );
  70.           }
  71.       }
  72.   }
  73.  
  74. void ApplicationBase::OpenApplication( const AEEvent& event,
  75.                                                     AEEvent& )
  76.   {
  77.     event.ThrowMissedParameter();
  78.     
  79.     if ( !CanCreate() )
  80.         throw OSError( errAEEventFailed );
  81.     
  82.     Create();
  83.   }
  84.  
  85. void ApplicationBase::OpenDocuments( const AEEvent&,
  86.                                                  AEEvent& )
  87.   {
  88.     throw OSError( errAEEventNotHandled );
  89.   }
  90.  
  91. void ApplicationBase::PrintDocuments( const AEEvent&,
  92.                                                   AEEvent& )
  93.   {
  94.     throw OSError( errAEEventNotHandled );
  95.   }
  96.  
  97. void ApplicationBase::QuitApplication( const AEEvent&,
  98.                                                     AEEvent& )
  99.   {
  100.     Quitting& quitter( Quitter::The() );
  101.     
  102.     if ( !quitter.CanStartQuitting() )
  103.         throw OSError( errAEEventFailed );
  104.     
  105.     quitter.StartQuitting();
  106.   }
  107.